<?php
/**
 * 预约
 * Author: 毛康燕
 * Date: 2021/6/17
 */
namespace app\api\controller\v1;

use app\common\model\Subscribe as SubscribeModel;
use app\common\model\Classify as ClassifybeModel;

class Subscribe extends BaseController
{
    //预约项目
    public function index()
    {
        $model = new ClassifybeModel();
        $res = $model
            ->field('id,title')
            ->select()
            ->toArray();
        return sucessMsg(200, '获取成功！', ['res' => $res]);
    }

    //在线预约
    public function subscribe()
    {
        $list = $this->request->param();
        if ($this->request->isPost() && !empty($list)) {
            $this->model = new SubscribeModel();
            if ((isset($list['name']) && isset($list['phone']) && isset($list[' birthday']) && isset($list['sex']) && isset($list['time']) && isset($list['classify_id']))) {
                return errMsg('请填写完整信息');
            }
            if (!preg_match('~1(3|4|5|7|8)[0-9]\d{8}$~', $list['phone'])) {
                return errMsg('手机号格式不正确');
            }
            $list['created_at'] = time();
            $about = $this->model->insert($list);
            if (empty($edit)) {
                return sucessMsg(200, '成功！', ['list' => $list]);
            }
            return errMsg(422, '失败');
        }
        return errMsg('请添加信息');
    }
}